<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2018/7/20 0020
 * Time: 14:54
 */
namespace app\caipiao\controller;
use think\Controller;
use thinkcms\auth\Auth;
use think\Db;

class User extends Controller{
    public function _initialize(){
        parent::_initialize();

        header("Content-type:text/html;charset=utf-8");
    }

    public function login(){
        return $this->fetch();
    }

    public function isLogin(){

        $number=input('post.nickname');
        $pwd=input('post.password');

        $username_count = Db::name('admins')->where(array('nickname'=>$number))->field('id,nickname,relname,password,salt')->find();
        //dump($username);die;

        if(empty($username_count['id'])){
            return json(array('code'=>'0','msg'=>'该账号不存在!'));
        }

        if($username_count['password'] != md5(md5($pwd.$username_count['salt']))){
            return json(array('code'=>'0','msg'=>'密码错误'));
        }
        session('auth',$number);
        session('admin',$username_count['relname']);
        session('aid',$username_count['id']);
        $data=array('user'=>$number,'jilv'=>$number.'登录彩票杀率设置后台','time'=>time(),'ip'=>get_ip());
        Db::name('caipiao_jl')->insert($data);
        $this->redirect('/');
    }
}
